package com.yb.util.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.yb.domain.member.TsSysuser;
import com.yb.util.comm.Contants;

public class CheckSecurity extends TagSupport {

	private static final long serialVersionUID = 1L;
	String basePath;

	@SuppressWarnings("unchecked")
	public int doEndTag() throws JspException {
		try {
			HttpSession session = pageContext.getSession();
			JspWriter out = pageContext.getOut();
			TsSysuser baseInfo = (TsSysuser) session
					.getAttribute(Contants.SESSION_USER);
			HttpServletRequest request = (HttpServletRequest) pageContext
					.getRequest();
			String path = request.getContextPath();
			basePath = request.getScheme() + "://" + request.getServerName()
					+ ":" + request.getServerPort() + path + "/";
			if (null == baseInfo) {
				out.print("<script>window.location.href='" + basePath
						+ "login.html'</script>");
				return TagSupport.SKIP_PAGE;
			}
			out.print("");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

}
